package com.hongji.lms5xxcommunicator.grid.core;

import java.util.Arrays;

public class RasterState {
    public GridSpec spec;
    public double[][] sumZ;
    public int[][] count;
    public double[][] meanZ;
    public boolean[][] hasData;

    public RasterState(GridSpec spec) {
        this.spec = spec;
        this.sumZ = new double[spec.rows][spec.cols];
        this.count = new int[spec.rows][spec.cols];
        this.meanZ = new double[spec.rows][spec.cols];
        this.hasData = new boolean[spec.rows][spec.cols];
        for (int r = 0; r < spec.rows; r++) Arrays.fill(meanZ[r], Double.NaN);
    }

    public void clear() {
        for (int r = 0; r < spec.rows; r++) {
            Arrays.fill(sumZ[r], 0.0);
            Arrays.fill(count[r], 0);
            Arrays.fill(meanZ[r], Double.NaN);
            Arrays.fill(hasData[r], false);
        }
    }

    public boolean inBounds(int r, int c) {
        return r >= 0 && c >= 0 && r < spec.rows && c < spec.cols;
    }
}
